package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.system.service.ISysDeptService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ReBankBonus;
import com.ruoyi.system.service.IReBankBonusService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 银行开户积分设定Controller
 * 
 * @author ruoyi
 * @date 2023-12-21
 */
@Controller
@RequestMapping("/system/bankbonus")
public class ReBankBonusController extends BaseController
{
    private String prefix = "system/bankbonus";

    @Autowired
    private IReBankBonusService reBankBonusService;


    @Autowired
    private ISysDeptService deptService;

    @RequiresPermissions("system:bankbonus:view")
    @GetMapping()
    public String bankbonus()
    {
        return prefix + "/bankbonus";
    }

    /**
     * 查询银行开户积分设定列表
     */
    @RequiresPermissions("system:bankbonus:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReBankBonus reBankBonus)
    {
        startPage();
        List<ReBankBonus> list = reBankBonusService.selectReBankBonusList(reBankBonus);
        return getDataTable(list);
    }

    /**
     * 导出银行开户积分设定列表
     */
    @RequiresPermissions("system:bankbonus:export")
    @Log(title = "银行开户积分设定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReBankBonus reBankBonus)
    {
        List<ReBankBonus> list = reBankBonusService.selectReBankBonusList(reBankBonus);
        ExcelUtil<ReBankBonus> util = new ExcelUtil<ReBankBonus>(ReBankBonus.class);
        return util.exportExcel(list, "银行开户积分设定数据");
    }

    /**
     * 新增银行开户积分设定
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存银行开户积分设定
     */
    @RequiresPermissions("system:bankbonus:add")
    @Log(title = "银行开户积分设定", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReBankBonus reBankBonus)
    {
        reBankBonus.setCreateBy(getLoginName());
        if(reBankBonus.getOrgId()!=null){
            SysDept dept=deptService.selectDeptById(reBankBonus.getOrgId());
            reBankBonus.setOrgName(dept.getDeptName());
        }
        return toAjax(reBankBonusService.insertReBankBonus(reBankBonus));
    }

    /**
     * 修改银行开户积分设定
     */
    @RequiresPermissions("system:bankbonus:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ReBankBonus reBankBonus = reBankBonusService.selectReBankBonusById(id);
        mmap.put("reBankBonus", reBankBonus);
        return prefix + "/edit";
    }

    /**
     * 修改保存银行开户积分设定
     */
    @RequiresPermissions("system:bankbonus:edit")
    @Log(title = "银行开户积分设定", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReBankBonus reBankBonus)
    {
        reBankBonus.setUpdateBy(getLoginName());
        return toAjax(reBankBonusService.updateReBankBonus(reBankBonus));
    }

    /**
     * 删除银行开户积分设定
     */
    @RequiresPermissions("system:bankbonus:remove")
    @Log(title = "银行开户积分设定", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(reBankBonusService.deleteReBankBonusByIds(ids));
    }
}
